package com.lqkj.maptest.controller;

import com.lqkj.maptest.utils.SaveFile;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Linm
 * @title
 * @date 2021/8/19 9:05
 */
@RestController
public class UpLoadController {

    /**
     * 上传单个文件
     */
    @PostMapping("/upload")
    public Object upload(@RequestParam("file")MultipartFile file){
        return SaveFile.saveFile(file);
    }

    /**
     * 上传多个文件
     * @param files 多个文件
     * @return OK
     */
    @PostMapping("/multipartUpload")
    public Object multipartUpload(@RequestParam("file")MultipartFile[] files){
        System.out.println("文件的个数："+files.length);
        for (MultipartFile f : files) {
            SaveFile.saveFile(f);
        }
//        for (int i = 0; i <files.length ; i++) {
//            saveFile(files[i]);
//        }
        return "ok";
    }
}
